﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace FangDuShi_API.Common
{
    /// <summary>
    /// 引入DLL的相关操作函数
    /// </summary>
    public class ImportDllApiUtil
    {
        #region Wibukey加密锁相关操作函数

        [DllImport("ImportDlls/WibukeyReal6.dll")]
        public static extern string GetFirmName(int Firmcode, int Usercode, string Signature);

        [DllImport("ImportDlls/WibukeyReal6.dll")]
        public static extern string GetDBName(int Firmcode, int Usercode, string Signature);

        [DllImport("ImportDlls/WibukeyReal6.dll")]
        public static extern string GetPassword(int Firmcode, int Usercode, string Signature);

        [DllImport("ImportDlls/WibukeyReal6.dll")]
        public static extern string GetLogid(int Firmcode, int Usercode, string Signature);

        [DllImport("ImportDlls/WibukeyReal6.dll")]
        public static extern string CheckSignature(int Firmcode, int Usercode, string Signature);

        [DllImport("ImportDlls/APSDNS2IP.dll")]
        public static extern string GetDNS2IP(string HostName);

        #endregion
        #region  应用系统加解密相关操作函数
        [DllImport("ImportDlls/Encryptor.dll")]
        public static extern string Encrypt(string as_line, string as_key);

        [DllImport("ImportDlls/Encryptor.dll")]
        public static extern string Decrypt(string as_line, string as_key);

        #endregion

        #region 应用系统图片相关操作函数
        [DllImport("ImportDlls/apsimage.dll")]
        public static extern bool GetImageSize(string lpszPathName, ref uint dwWidth, ref uint dwHeight);

        [DllImport("ImportDlls/apsimage.dll")]
        public static extern bool Resample(string lpszSrcPathName, string lpszDestPathName, int newWidth, int newHeight);

        #endregion

        #region 其他相关操作
        [DllImport("Kernel32.dll")]
        public static extern int SetLocalTime(ref str_SystemTime systimeptr);//设置本地时间
        [StructLayout(LayoutKind.Sequential)]
        public struct str_SystemTime
        {
            public ushort wYear;
            public ushort wMonth;
            public ushort wDayOfWeek;
            public ushort wDay;
            public ushort wHour;
            public ushort wMinute;
            public ushort wSecond;
            public ushort wMiliseconds;

        }
        /// <summary>
        /// windows窗体操作
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="bEnable"></param>
        /// <returns></returns>
        [DllImport("user32", CharSet = CharSet.Auto)]
        public static extern int EnableWindow(IntPtr hwnd, bool bEnable);


        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, Int32 flags);
        [DllImport("user32.dll")]
        public static extern bool SetWindowPos(IntPtr hWnd, Int32 hWndInsertAfter, Int32 X, Int32 Y, Int32 cx, Int32 cy, uint uFlags);
        /*
        [DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
        public static extern int GetSystemDefaultLCID();

        [DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
        public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
        public const int LOCALE_SLONGDATE = 0x20;
        public const int LOCALE_SSHORTDATE = 0x1F;
        public const int LOCALE_STIME = 0x1003;
        public const int LOCALE_ITIME = 0x00000023;
        /// <summary>
        /// 修改本地时间
        /// </summary>
        public static void SetDateTimeFormat()
        {
            try
            {
                int x = GetSystemDefaultLCID();
                SetLocaleInfo(x, LOCALE_ITIME, "HH:mm");   
                SetLocaleInfo(x, LOCALE_STIME, "HH:mm:ss");        //时间格式
                SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-MM-dd");   //短日期格式  
                SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy-MM-dd");   //长日期格式 
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

        }
         * */
        #endregion


        #region 身份证类国腾（termb.dll）
        /// <summary>
        /// 初始化串口;
        /// </summary>
        /// <param name="iPort"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int InitComm(int iPort);
        /// <summary>
        /// 关闭串口
        /// </summary>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int CloseComm();
        /// <summary>
        /// 卡认证
        /// </summary>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int Authenticate();
        /// <summary>
        /// 读卡操作。
        /// </summary>
        /// <param name="iActive"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int Read_Content(int iActive);
        /// <summary>
        /// 得到姓名信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPeopleName(Byte[] buf, int iLen);
        /// <summary>
        /// 得到性别信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPeopleSex(Byte[] buf, int iLen);
        /// <summary>
        /// 得到民族信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPeopleNation(Byte[] buf, int iLen);
        /// <summary>
        /// 得到发证机关信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetDepartment(Byte[] buf, int iLen);
        /// <summary>
        /// 得到出生日期
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPeopleBirthday(Byte[] buf, int iLen);
        /// <summary>
        /// 得到地址信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPeopleAddress(Byte[] buf, int iLen);
        /// <summary>
        /// 得到有效启始日期
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetStartDate(Byte[] buf, int iLen);
        /// <summary>
        /// 得到有效截止日期
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetEndDate(Byte[] buf, int iLen);

        /// <summary>
        /// 得到卡号信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPeopleIDCode(Byte[] buf, int iLen);

        /// <summary>
        /// 得到图片信息
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="iLen"></param>
        /// <returns></returns>
        [DllImport("termb.DLL", CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPhotoBMP(Byte[] buf, int iLen);

        #endregion

    }


}
